package com.cjj;


import ohos.agp.window.service.DisplayManager;
import ohos.app.Context;

import java.math.BigDecimal;

public class Util {

    public static int dip2px(Context context, float dpValue) {
        final float scale = DisplayManager.getInstance().getDefaultDisplay(context).get().getAttributes().scalDensity;
        return (int) (new BigDecimal(dpValue).multiply(new BigDecimal(scale)).add(new BigDecimal(0.5f)).floatValue());
    }

    public static float limitValue(float a, float b) {
        float valve = 0;
        final float min = Math.min(a, b);
        final float max = Math.max(a, b);
        valve = valve > min ? valve : min;
        valve = valve < max ? valve : max;
        return valve;
    }
}
